/*    */ package dm.jdbc.dataConvertion;
/*    */ 
/*    */ import java.io.ByteArrayInputStream;
/*    */ import java.io.InputStream;
/*    */ import java.io.Reader;
/*    */ import java.io.SequenceInputStream;
/*    */ import java.util.Enumeration;
/*    */ import java.util.HashMap;
/*    */ import java.util.Map;
/*    */ 
/*    */ public class ReaderToInputStream
/*    */ {
/*    */   public InputStream ReaderTo(Reader reader, String serverEncoding, long destLen)
/*    */   {
/* 15 */     return new SequenceInputStream(new InputStreamEnumerator(reader, 
/* 16 */       serverEncoding, destLen));
/*    */   }
/*    */   
/*    */   public InputStream ReaderTo(Reader reader, String serverEncoding) {
/* 20 */     return new SequenceInputStream(new InputStreamEnumerator(reader, 
/* 21 */       serverEncoding));
/*    */   }
/*    */   
/*    */   class InputStreamEnumerator implements Enumeration
/*    */   {
/* 26 */     private Reader m_reader = null;
/* 27 */     private long m_destLen = 0L;
/* 28 */     private long m_hasReadLen = 0L;
/* 29 */     private boolean m_hasDestLen = false;
/* 30 */     private String m_serverEncoding = null;
/* 31 */     private int m_Index = 0;
/* 32 */     private Map m_inputStream = new HashMap();
/*    */     
/*    */     public InputStreamEnumerator(Reader reader, String serverEncoding, long destLen)
/*    */     {
/* 36 */       this.m_reader = reader;
/* 37 */       this.m_serverEncoding = serverEncoding;
/* 38 */       this.m_destLen = destLen;
/* 39 */       this.m_hasDestLen = true;
/* 40 */       this.m_hasReadLen = 0L;
/*    */     }
/*    */     
/*    */     public InputStreamEnumerator(Reader reader, String serverEncoding) {
/* 44 */       this.m_reader = reader;
/* 45 */       this.m_serverEncoding = serverEncoding;
/* 46 */       this.m_destLen = 0L;
/* 47 */       this.m_hasDestLen = false;
/* 48 */       this.m_hasReadLen = 0L;
/*    */     }
/*    */     
/*    */     public boolean hasMoreElements() {
/* 52 */       int bufLen = 32000;
/* 53 */       if ((this.m_hasDestLen) && (bufLen > this.m_destLen - this.m_hasReadLen)) {
/* 54 */         bufLen = (int)(this.m_destLen - this.m_hasReadLen);
/*    */       }
/* 56 */       char[] charsTemp = new char[bufLen];
/* 57 */       byte[] bytesTemp = null;
/* 58 */       String strTemp = null;
/* 59 */       int len = 0;
/*    */       try {
/* 61 */         if ((len = this.m_reader.read(charsTemp, 0, charsTemp.length)) > 0) {
/* 62 */           strTemp = new String(charsTemp, 0, len);
/* 63 */           if (this.m_serverEncoding != null) {
/* 64 */             bytesTemp = strTemp.getBytes(this.m_serverEncoding);
/*    */           } else {
/* 66 */             bytesTemp = strTemp.getBytes();
/*    */           }
/* 68 */           this.m_inputStream.put(new Integer(this.m_Index), 
/* 69 */             new ByteArrayInputStream(bytesTemp, 0, 
/* 70 */             bytesTemp.length));
/*    */           
/* 72 */           if (this.m_hasDestLen) {
/* 73 */             this.m_hasReadLen += len;
/*    */           }
/* 75 */           return true;
/*    */         }
/*    */       } catch (Exception e) {
/* 78 */         e.printStackTrace();
/*    */       }
/* 80 */       return false;
/*    */     }
/*    */     
/*    */     public Object nextElement() {
/* 84 */       ByteArrayInputStream ret = (ByteArrayInputStream)this.m_inputStream
/* 85 */         .get(new Integer(this.m_Index));
/*    */       
/* 87 */       this.m_Index += 1;
/*    */       
/* 89 */       return ret;
/*    */     }
/*    */   }
/*    */ }


/* Location:              D:\Program Files\DBMS_20150813\jdbc\Dm7JdbcDriver17.jar!\dm\jdbc\dataConvertion\ReaderToInputStream.class
 * Java compiler version: 2 (46.0)
 * JD-Core Version:       0.7.1
 */